package com.p2p.service.operationsManagementService.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.p2p.common.base.RespResult;
import com.p2p.common.base.RespResultCode;
import com.p2p.entity.NewcomerStrategy;
import com.p2p.mapper.NewcomerStrategyMapper;
import com.p2p.service.operationsManagementService.NewcomerStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewcomerStrategyServiceImpl implements NewcomerStrategyService {

    @Autowired
    private NewcomerStrategyMapper newcomerStrategyMapper;

    @Override
    public RespResult findNewcomerStrategyList() {
        QueryWrapper<NewcomerStrategy> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_deleted",0);
        List<NewcomerStrategy> newcomerStrategyList = newcomerStrategyMapper.selectList(queryWrapper);
        if (newcomerStrategyList.size() > 0){
            return RespResult.success(newcomerStrategyList);
        }
        return RespResult.error(RespResultCode.ERR_PARAM_NOT_LEGAL.getCode(),RespResultCode.ERR_PARAM_NOT_LEGAL.getMessage(),null);
    }

    @Override
    public RespResult updateNewcomerStrategy(NewcomerStrategy newcomerStrategy) {

        int i = newcomerStrategyMapper.updateById(newcomerStrategy);
        if (i > 0){
            return RespResult.success();
        }
        return RespResult.error(RespResultCode.ERR_PARAM_NOT_LEGAL.getCode(),RespResultCode.ERR_PARAM_NOT_LEGAL.getMessage(),null);
    }
}
